import 'package:flutter/material.dart';

class MyApp11 extends StatelessWidget {
  // 2. 设置默认值
  const MyApp11({
    super.key,
    this.title = '',
    this.content = '',
    this.tColor = Colors.orange,
    this.cColor = Colors.yellow,
  });

  // 1. 定义属性
  final String title;
  final String content;
  final Color tColor;
  final Color cColor;

  // 重写build 返回需要封装的组件即可
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.purple,
          title: Center(
            child: Text(
              '标题为:$title',
              style: TextStyle(
                  color: tColor, fontSize: 30, fontWeight: FontWeight.w900),
            ),
          ),
        ),
        // 1.2 主体部分
        body: const MyContainer(),
      ),
    );
  }
}

class MyContainer extends StatelessWidget {
  const MyContainer({super.key});

  @override
  Widget build(BuildContext context) {
    return ListView.separated(
      itemBuilder: (BuildContext context, int index) {
        return Container(
          height: 200,
          color: Colors.red,
          child: Text(
            '$index',
            style: TextStyle(fontSize: 100, color: Colors.white),
          ),
        );
      },
      separatorBuilder: (BuildContext context, int index) {
        return Container(
          height: 20,
          color: Colors.yellow,
          child: Image.network(
              'https://pinoss.com/pdan123/i/pdan1/2024/5/P14.jpg'),
        );
      },
      itemCount: 1000,
    );
  }
}

class MyContainer_build extends StatelessWidget {
  const MyContainer_build({super.key});

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemBuilder: (BuildContext context, int index) {
        return Container(
          height: 200,
          color: Colors.red,
          child: Text(
            '$index',
            style: TextStyle(fontSize: 100, color: Colors.white),
          ),
        );
      },
      itemCount: 1000,
    );
  }
}

class MyContainer_normal_use extends StatelessWidget {
  const MyContainer_normal_use({super.key});

  @override
  Widget build(BuildContext context) {
    return ListView(
      scrollDirection: Axis.vertical,
      // physics: const NeverScrollableScrollPhysics(),
      children: [
        Container(
          height: 200,
          color: Colors.red,
        ),
        Container(
          height: 200,
          color: Colors.orange,
        ),
        Container(
          height: 200,
          color: Colors.yellow,
        ),
        Container(
          height: 200,
          color: Colors.green,
        ),
        Container(
          height: 200,
          color: Colors.greenAccent,
        ),
        Container(
          height: 200,
          color: Colors.blue,
        ),
        Container(
          height: 200,
          color: Colors.purple,
        ),
      ],
    );
  }
}
